package org.ne.springboot.mapper;

import org.apache.ibatis.annotations.*;
import org.ne.springboot.pojo.Article;
import org.ne.springboot.pojo.Category;

import java.util.List;

/**
 * @author wey
 * @Date 2025/1/2 下午8:52 1月
 */

@Mapper
public interface ArticleMapper {


    @Insert("insert into article(title, content, cover_img, state, category_id, create_user, create_time, update_time, fk_article_category, fk_article_user) " +
            "values(#{title},#{content},#{coverImg},#{state},#{categoryId},#{createUser}, #{createTime},#{updateTime},#{categoryId},#{createUser})")
    void add(Article article);

    List<Article> list(Integer userId, String categoryId, String state);

    @Delete("delete from article where id=#{id}")
    void delete(Integer id);

    @Select("select * from article where create_user=#{userId} and id=#{id}")
    Article findById(@Param("id") Integer id, @Param("userId") Integer userId);

    // @Update("update category set category_name=#{categoryName},category_alias=#{categoryAlias},update_time=#{updateTime} where id=#{id}")
    @Update("update article set title=#{title}, content=#{content}, cover_img=#{coverImg} ,state=#{state}, category_id=#{categoryId} where id=#{id}")
    void update(Article article);
}
